// 2013-8-1下午04:52:58  net.betou.trade.entity.main.Trade.java

package net.betou.trade.entity.main;

import java.util.Date;

import org.apache.commons.lang.StringUtils;

import net.betou.common.util.DataConvertUtils;
import net.betou.trade.entity.main.base.BaseTrade;

/**
 * 
 * @author 叶装装
 */
public class Trade extends BaseTrade{

	private static final int point = 2; // 保留的小数点
	
	private static final long serialVersionUID = -1533755316173126460L;
	
	private Boolean send; // 是否立即发送短信
	
	public Trade( ){}
	
	public void initToOpenSave( ){
		
		if( getStartDate( ) == null ){
			this.setStartDate( new Date( ) );
		}
		
		if( StringUtils.isBlank( getOpenReason( ) )){
			setOpenReason( null );
		}
		this.setStatus( true ); // 表示开仓
	}
	
	public void initToCloseSave( ){
		if( getEndDate( ) == null ){
			this.setEndDate( new Date( ) );
		}
		
		if( StringUtils.isBlank( getCloseReason() )){
			setCloseReason( null );
		}
		this.setStatus( false ); // 表示平仓
	}
	
	public void initToCloseUpdate( ){
		if( StringUtils.isBlank( getCloseReason() )){
			setCloseReason( null );
		}
	}
	
	public Integer [ ] getGroups( ){
		String [ ] splitId = StringUtils.split( this.getOrientedGroup( ), "," );
		Integer [ ] ids = new Integer[ splitId.length ];
		
		for( int i = 0; i < splitId.length; i++ ){
			ids[ i ] = DataConvertUtils.getInt( splitId[ i ] );
		}
		
		return ids;
	}
	
	public Integer [ ] getSmsGroup( ){
		if(StringUtils.isBlank(  this.getSmsGroups( ) ) ){
			return null;
		}
		String [ ] splitId = StringUtils.split( this.getSmsGroups( ), "," );
		Integer [ ] ids = new Integer[ splitId.length ];
		
		for( int i = 0; i < splitId.length; i++ ){
			ids[ i ] = DataConvertUtils.getInt( splitId[ i ] );
		}
		
		return ids;
	}
	
	public String getFormatOpenPosition( ){
		return DataConvertUtils.formatDouble( point, getOpenPosition( ) );
	}
	
	public String getFormatClosePosition( ){
		return DataConvertUtils.formatDouble( point,  getClosePosition( ) );
	}
	
	public String getFormatStopPosition( ){
		return DataConvertUtils.formatDouble( point,  getStopPosition( ) ); 
	}
	
	public String getFormatLongPosition( ){
		return DataConvertUtils.formatDouble( point,  getLongPosition( ) ); 
	}
	
	public String getFormatProfil( ){
		return DataConvertUtils.formatDouble( point,  getProfit( ) ); 
	}

	public Boolean getSend( ) {
		return send;
	}

	public void setSend( Boolean send ) {
		this.send = send;
	}
	
	

}
